/*

    This file is part of GLua

    GLua Development Environment
    Copyright (C) 2007 VoiDeD

    GLua is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    GLua is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GLua
{
    // this is a dialog used when a new project is being created
    public partial class ProjectDialog : Form
    {
        public ProjectDialog()
        {
            InitializeComponent();

            comboBox1.SelectedIndex = 0;
            imageList1.Images.Add( "empty_project", global::GLua.Properties.Resources.empty_project );


            foreach ( ProjectTemplate pt in Templates.ProjectTemps )
            {
                ListViewItem lvi = new ListViewItem();
                lvi.ImageKey = "empty_project";
                lvi.StateImageIndex = 0;
                lvi.Text = pt.Name;
                lvi.Tag = pt;
                lvi.Group = listView1.Groups[0];

                listView1.Items.Add( lvi );
            }
            listView1.Items[0].Selected = true;
        }

        private void button3_Click( object sender, EventArgs e )
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.Description = "Please choose the directory to save the project at.";
            fbd.ShowNewFolderButton = true;

            if ( fbd.ShowDialog() != DialogResult.OK )
                return;

            textBox3.Text = fbd.SelectedPath;
        }
        private void listView1_SelectedIndexChanged( object sender, EventArgs e )
        {
            UpdateEnable();
            if ( listView1.SelectedItems.Count > 0 )
                textBox2.Text = ( ( ProjectTemplate )listView1.SelectedItems[0].Tag ).DefaultName;
        }
        private void textBox2_TextChanged( object sender, EventArgs e )
        {
            UpdateEnable();
        }
        private void textBox3_TextChanged( object sender, EventArgs e )
        {
            UpdateEnable();
        }

        private void UpdateEnable()
        {
            if ( listView1.SelectedItems.Count > 0 )
            {
                ProjectTemplate project = ( ProjectTemplate )listView1.SelectedItems[0].Tag;
                textBox1.Text = project.Description;
                textBox2.Enabled = true;
                textBox3.Enabled = true;
                textBox4.Enabled = true;
                button3.Enabled = true;

                if ( project.AllowType )
                    comboBox1.Enabled = true;

                if ( ( textBox2.Text.Length > 0 ) && ( textBox3.Text.Length > 0 ) )
                {
                    button1.Enabled = true;
                }
                else
                {
                    button1.Enabled = false;
                }
            }
            else
            {
                textBox2.Enabled = false;
                textBox3.Enabled = false;
                textBox4.Enabled = false;
                button1.Enabled = false;
                button3.Enabled = false;
            }
        }

        public string ProjectName
        {
            get { return textBox2.Text; }
        }
        public string ProjectDescription
        {
            get { return textBox4.Text; }
        }
        public ProjectType ProjectType
        {
            get
            {
                ProjectTemplate project = ( ProjectTemplate )listView1.SelectedItems[0].Tag;

                if ( project.AllowType )
                {
                    ProjectType type = ( ProjectType )Enum.Parse( typeof( ProjectType ), comboBox1.Text );
                    return type;
                }
                else
                {
                    return project.ForcedType;
                }
            }
        }
        public string ProjectPath
        {
            get { return textBox3.Text; }
        }

    }
}